﻿using HR60_PanelSoft.Model;
using HR60_PanelSoft.Model.BaseModel;
using HR60_PanelSoft.NetWork.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HR60_PanelSoft.NetWork.Sender
{
    class Sender_0110:BaseSender
    {
        public Sender_0110(byte panelNo, Panel panel)
        {
            if(panel.m485Pin==null)
                return;

            byte[] data = new byte[8];

            Device device = panel.m485Pin.getConnectedDevice();
            if (device == null)
                return;
            if(device.type.name == "多楼层主机")
            {
                data[0] = 1;
                int i = 1;
                List<Net> nets = Proj.currentProj.nets;
                foreach (Net net in nets)
                {
                    if (i == 7)
                        break;
                    List<Panel> panels = net.panels;
                    
                    foreach (Panel d in panels)
                    {
                        if(d.m485Pin ==null)
                            continue;

                        if (d.m485Pin.getConnectedDevice().type.name == "多楼层从机")
                        {
                            data[i++] = (byte)net.index;
                            if (i == 7)
                                break;
                        }
                    }

                }
            }
            else if (device.type.name == "多楼层从机")
            {
                data[0] = 2;
              
            }
            else if (device.type.name == "中央空调系统")
            {
                data[0] = 3;

                  List<DeviceGroup> deviceGroups = Proj.currentProj.deviceGroups;
                foreach (DeviceGroup dg in deviceGroups)
                {
                    List<Device> devices = dg.devices;
                    foreach (Device d in devices)
                    {

                        if (d.type.exType == ExDeviceType.CentralAircon)
                        { 
                                data[1] = Convert.ToByte(d.brand.protocolTag) ;  
                                goto labe1;
                        }
                    }

                }
            labe1: ;

            }
            else if (device.type.name == "中央供暖系统")
            {
                data[0] = 4;

                List<DeviceGroup> deviceGroups = Proj.currentProj.deviceGroups;
                foreach (DeviceGroup dg in deviceGroups)
                {
                    List<Device> devices = dg.devices;
                    foreach (Device d in devices)
                    {

                        if (d.type.exType == ExDeviceType.CentralHeating)
                        {
                            data[1] = Convert.ToByte(d.brand.protocolTag);
                            goto labe2;
                        }
                    }

                }
            labe2: ;

            }
            else if (device.type.name == "新风系统系统")
            {
                data[0] = 5;
                List<DeviceGroup> deviceGroups = Proj.currentProj.deviceGroups;
                foreach (DeviceGroup dg in deviceGroups)
                {
                    List<Device> devices = dg.devices;
                    foreach (Device d in devices)
                    {

                        if (d.type.exType == ExDeviceType.CentralNewWind)
                        {
                            data[1] = Convert.ToByte(d.brand.protocolTag);
                            goto labe3;
                        }
                    }

                }
            labe3: ;
            }

            else if (device.type.name == "背景音乐系统")
            {
                data[0] = 6;
                List<DeviceGroup> deviceGroups = Proj.currentProj.deviceGroups;
                foreach (DeviceGroup dg in deviceGroups)
                {
                    List<Device> devices = dg.devices;
                    foreach (Device d in devices)
                    {

                        if (d.type.exType == ExDeviceType.BGM)
                        {
                            data[1] = Convert.ToByte(d.brand.protocolTag);
                            goto labe4;
                        }
                    }

                }
            labe4: ;
            }
            else if (device.type.name == "智能终端(灯光窗帘)")
            {
                data[0] = 7;
            }
            else if (device.type.name == "智能终端（全部功能）")
            {
                data[0] = 8;
            }
            else if (device.type.name == "照明调光控制器")
            {
                data[0] = 9;
            }
            else if (device.type.name == "耶鲁智能锁")
            {
                data[0] = 10;
            }
            else if (device.type.name == "煤气阀2")
            {
                data[0] = 11;
            }
            else if (device.type.name == "煤气阀3")
            {
                data[0] = 12;

            }
            else if (device.type.name == "煤气阀4")
            {
                data[0] = 13;
            }
            else if (device.type.name == "门锁1")
            {
                data[0] = 14;
            }
            else if (device.type.name == "433窗帘")
            {
                data[0] = 15;
            }
            else if (device.type.name == "拓宝房车控制器")
            {
                data[0] = 16;
            }




            this.package = Package.getPackage(0x01, 0x10, panelNo, 0x01, data);

        }
    }
}
